<?php

//会员
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('foreground');

class other extends foreground {

    public function __construct() {
        parent::__construct();
    }

    //播放历史
    public function seehistory() {
        $uid = (int)param::get_cookie('_userid');
        $apply_expert = pc_base::load_model('apply_expert_model');
        $SuperStar = pc_base::load_model('SuperStar_model');
        $arr=$apply_expert->select("uid=".$uid,'a_id');
        $Star='';
        foreach ($arr as &$v) {
            $Stars=$SuperStar->get_one('id='.$v['a_id']);
            if ($Stars['status']==99) {
                $Star[]=$Stars;
            }
        }

        include template('member', 'other_seehistory');
    }
    public function clearall() {
        $uid = (int)param::get_cookie('_userid');
        $sql="DELETE FROM phpcms_apply_expert WHERE uid=".$uid;
        $apply_expert_model = pc_base::load_model('apply_expert_model');
        $apply_expert_model->query($sql);
        echo '<script type="text/javascript">window.location.href="index.php?m=member&c=other&a=seehistory";</script>';
    }
    //消息提醒
    public function message() {
        $uid = (int)param::get_cookie('_userid');

        $db1 = pc_base::load_model('remind_model');
        $db2 = pc_base::load_model('reminds_model');

        $arr1 = $db1->select(['status' => 99]);
        $arr2 = $db2->select(['uid' => $uid]);

        foreach (array_merge($arr1, $arr2) as $r) {
            $time = $r['type'] == 0 ? $r['inputtime'] : strtotime($r['ymdhis']);
            $url = $r['type'] == 0 ? $r['url'] : APP_PATH . '?m=member&c=other&a=message_info&id=' . $r['id'];
            $arr[$time] = [
                'url' => $url,
                'time' => $time,
                'type' => $r['type'],
                'title' => $r['title'],
                //'small_content' => strip_tags($r['small_content']),
            ];
        }

        krsort($arr);

        include template('member', 'other_message');
    }

    //消息提醒 详情
    public function message_info() {
        $uid = (int)param::get_cookie('_userid');
        $CATEGORYS = getcache('category_content_1', 'commons');
        $catid = 3;

        $id = (int)$_GET['id'];

        $db = pc_base::load_model('reminds_model');
        $r = $db->get_one(['uid' => $uid, 'id' => $id]);

        if ($r) {
            $inputtime = $r['ymdhis'];
            $small_content = $r['small_content'];
            $type = $r['type'];
            $readed = $r['readed'];
            if ($readed != 1) {
                $where = 'uid=' . $uid . ' AND id =' . $id;
                $db->update(array('readed' => 1), $where);
            }
        } else {
            error_m('非法请求');
        }

        include template('content', 'show_remind');
    }

    //意见反馈
    public function feedback() {
        $uid = (int)param::get_cookie('_userid');

        if (!$_POST) {
            $info = $this->memberinfo;
            include template('member', 'other_feedback');
            exit();
        }

        //数据
        $realname = isset($_POST['realname']) ? safe_replace($_POST['realname']) : '';
        $qq = isset($_POST['qq']) ? safe_replace($_POST['qq']) : '';
        $email = isset($_POST['email']) ? safe_replace($_POST['email']) : '';
        $content = isset($_POST['content']) ? safe_replace($_POST['content']) : '';

        if (!$content) {
            json_exit(1, 200, '请输入留言内容');
        }

        $this->db_feedback = pc_base::load_model('feedback_model');

        //记录订单
        $res = $this->db_feedback->insert([
            'uid' => $uid,
            'realname' => $realname,
            'qq' => $qq,
            'email' => $email,
            'content' => $content,
            'ip' => ip(),
            'ymd' => date('Y-m-d'),
            'ymdhis' => date('Y-m-d H:i:s'),
        ]);

        json_exit(1, 100, '感谢您的留言');
    }

    //购买记录
    public function buylist() {
        $uid = (int)param::get_cookie('_userid');

        $this->db_mall = pc_base::load_model('mall_model');
        $arr = $this->db_mall->select(['uid' => $uid], '*', '', 'ymdhis desc');

        $this->db_shop = pc_base::load_model('shop_model');

        include template('member', 'other_buylist');
    }

    //常见问题&规则
    public function faq() {
        include template('member', 'other_faq');
    }

    //经验值规则
    public function exvalue() {
        include template('member', 'other_exvalue');
    }
    //网站建设中的页面
    public function builting() {
        include template('member', 'other_builting');
    }

}